#include<iostream>
#include<unordered_set>
using namespace std;
const int N = 7;
int arr[N][N];	
int k, n, m;
unordered_set<int>S;
int ans;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
void dfs(int x, int y, int step, int sum)
{
	if (step == k) {
		if (!S.count(sum)) {
			//cout << "sum----->" << sum << endl;
			S.insert(sum);
			ans++;
		}
		return;
	}
	for (int i = 0; i < 4; i++) {
		int a = dx[i] + x;
		int b = dy[i] + y;
		if (a<1 || a>n || b<1 || b>m)continue;
		dfs(a, b, step + 1, sum * 10 + arr[a][b]);
	}
}
int main()
{
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> arr[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dfs(i, j, 0, arr[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}